var currentTime;
var currentOffset = 1;
var currentOffset_ex = 1;
var tim;
var banner_show_time = 12;
var show_banner = 0;
var isDetectUser = 0;
var isDEbanner = 0;

var sec = {s0:[272,473,476,481,496,603,767],s36:[],s39:[],s55:[],s37:[],s56:[],s57:[],s38:[],s40:[],s42:[],}
/* Fix IE8 Object.keys */
if (!Array.prototype.indexOf) {
	Array.prototype.indexOf = function (obj, start) {
		for (var i = (start || 0), j = this.length; i < j; i++) {
			if (this[i] === obj) {
				return i;
			}
		}
		return -1;
	}
}

/* Fix IE8 Object.keys */
if (!Object.keys) Object.keys = function (o) {
	if (o !== Object(o))
		throw new TypeError('Object.keys called on non-object');
	var ret = [], p;
	for (p in o) if (Object.prototype.hasOwnProperty.call(o, p)) ret.push(p);
	return ret;
}

Date.prototype.getLSHFormatDate = function (str) {
	var format = function (number) {
		var chars = '0';
		var r = 10;

		for (; parseInt(number, 10) < r && r > 1; r /= 10) {
			number = chars.toString() + number;
		}

		return number.toString();
	};

	var months = ["Januar", "February", "Mart", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
	var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
	var d = this;

	var result = str.replace(/%([aAbBCdegGHIjmMpPSuUVwWyY%])/g,
		function (m0, m1) {
			switch (m1) {
				case 'H':
					return format(d.getHours());
				case 'M':
					return format(d.getMinutes());
				case 'd':
					return format(d.getDate());
				case 'm':
					return format(d.getMonth() + 1);
				case 'Y':
					return d.getFullYear();
				case 'A':
					return days[d.getDay()];
				case 'B':
					return months[d.getMonth()];
				default:
					'';
			}
		}
	);

	return result;
}

function cookie(name, value, options) {
	if (typeof value != 'undefined') {
		options = options || {};
		if (value === null) {
			value = '';
			options.expires = -1;
		}
		var expires = '';
		if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
			var date;
			if (typeof options.expires == 'number') {
				date = new Date();
				date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
			} else {
				date = options.expires;
			}
			expires = '; expires=' + date.toUTCString();
		}
		var path = options.path ? '; path=' + (options.path) : '';
		var domain = options.domain ? '; domain=' + (options.domain) : '';
		var secure = options.secure ? '; secure' : '';
		document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
	} else {
		var cookieValue = null;
		if (document.cookie && document.cookie != '') {
			var cookies = document.cookie.split(';');
			for (var i = 0; i < cookies.length; i++) {
				var cookie = cookies[i].replace(/^\s\s*/, '').replace(/\s\s*$/, '');
				if (cookie.substring(0, name.length + 1) == (name + '=')) {
					cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
					break;
				}
			}
		}
		return cookieValue;
	}
}
;

function Id(el) {
	return document.getElementById(el);
}

function getQueryVariable(variable, def) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");

	for (var i = 0; i < vars.length; i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
	}
	return def;
}

function bindReady(handler) {
	var called = false

	function ready() {
		if (called) return
		called = true
		handler()
	}

	if (document.addEventListener) {
		document.addEventListener("DOMContentLoaded", function () {
			ready()
		}, false)
	} else if (document.attachEvent) {
		if (document.documentElement.doScroll && window == window.top) {
			function tryScroll() {
				if (called) return
				if (!document.body) return
				try {
					document.documentElement.doScroll("left")
					ready()
				} catch (e) {
					setTimeout(tryScroll, 0)
				}
			}

			tryScroll()
		}

		document.attachEvent("onreadystatechange", function () {

			if (document.readyState === "complete") {
				ready()
			}
		})
	}

	if (window.addEventListener) window.addEventListener('load', ready, false)
	else if (window.attachEvent) window.attachEvent('onload', ready)
}

readyList = [];

function onReady(handler) {
	if (!readyList.length) {
		bindReady(function () {
			for (var i = 0; i < readyList.length; i++) {
				readyList[i]()
			}
		})
	}
	readyList.push(handler)
}

function getElementsByClassName(classList, node) {
	var node = node || document,
		list = node.getElementsByTagName('*'),
		length = list.length,
		classArray = classList.split(/\s+/),
		classes = classArray.length,
		result = [],
		i, j
	for (i = 0; i < length; i++) {
		for (j = 0; j < classes; j++) {
			if (list[i].className.search('\\b' + classArray[j] + '\\b') != -1) {
				result.push(list[i])
				break
			}
		}
	}
	return result
}

function hasClass(ele, cls) {
	return ele.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
}

function addClass(ele, cls) {
	if (ele && !this.hasClass(ele, cls)) ele.className += " " + cls;
}

function removeClass(ele, cls) {
	if (ele && hasClass(ele, cls)) {
		var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
		ele.className = ele.className.replace(reg, ' ');
	}
}

function toggle(el) {
	el.style.display = (el.style.display == 'none') ? '' : 'none'
}

function addEvent(elem, evType, fn) {
	if (elem.addEventListener) {
		elem.addEventListener(evType, fn, false)
		return fn;
	}

	iefn = function () {
		fn.call(elem)
	}
	elem.attachEvent('on' + evType, iefn);
	return iefn;
}

function getXmlHttp() {
	var xmlhttp;
	xmlhttp = false;

	if (window.ActiveXObject) {
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
				xmlhttp = false;
			}
		}
	}

	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

function getSection(sid, cats) {
	var req = getXmlHttp()
	req.onreadystatechange = function () {
		if (req.readyState == 4) {
			if (req.status == 200) {
				var lshcurrent = getElementsByClassName("lshcurrent", document);
				var notevents = document.querySelector('.notevents');

				lshcurrent[0].innerHTML += req.responseText;

				if (notevents) {
					lshcurrent[0].removeChild(document.querySelector('.notevents'));
				}

				var secevents = document.getElementById('secevents' + sid);
				if (secevents) {
					secevents.style.display = '';
				}

				changeEventsTime(currentOffset);
			}
		}
	}

	if (cats) {
		req.open('GET.html', '/static/s' + sid + '_' + cats.join('') + '.html', true);
	} else {
		req.open('GET.html', '/static/section' + sid + '.html', true);
	}
	req.send(null);
}

function getBets(eid) {
	if (document.querySelector('#bet_event' + eid) && document.querySelector('#bet_event' + eid).getAttribute('class').indexOf('isload') == -1) {
		if (!document.querySelector("#bet_event" + eid + " .betbanner").innerHTML)
			if(show_banner){
			  document.querySelector("#bet_event" + eid + " .betbanner").innerHTML = '<iframe align=top width=412 height=78 marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=0 scrolling=no src="http://mb.marathonbet.com/view.php?gid=460&amp;b_width=412&amp;b_height=78"></iframe>';
			}
		var req = getXmlHttp()
		req.onreadystatechange = function () {
			if (req.readyState == 4) {
				if (req.status == 200) {
					var res = eval('(' + req.responseText + ')');

					document.querySelector('#bet_event' + eid + ' .beturl').href = res.url;
					document.querySelector('#bet_event' + eid + ' #home').innerHTML = res.home;
					document.querySelector('#bet_event' + eid + ' #draw').innerHTML = res.draw;
					document.querySelector('#bet_event' + eid + ' #over').innerHTML = res.over;
					document.querySelector('#bet_event' + eid + ' #under').innerHTML = res.under;
					document.querySelector('#bet_event' + eid + ' #away').innerHTML = res.away;
					document.querySelector('#bet_event' + eid + ' #hcap1').innerHTML = res.hcap1;
					document.querySelector('#bet_event' + eid + ' #hcap2').innerHTML = res.hcap2;
					document.querySelector('#bet_event' + eid).setAttribute('class', document.querySelector('#bet_event' + eid).getAttribute('class') + ' isload');

					if(show_banner){
					  setTimeout(function () {
						document.querySelector("#bet_event" + eid + " .betbanner").style.display = "none";
						document.querySelector("#bet_event" + eid + " .beturl").style.display = "inline";
					  },banner_show_time * 1000);
					}else{
					  document.querySelector("#bet_event" + eid + " .beturl").style.display = "inline";
					}
				}
			}
		}
		req.open('GET.html', 'pr0e33.html?option=com_lsh&amp;task=getbets&amp;event_id=' + eid + '&bet_id=1&format=raw', true);
		req.send(null);
	}
}

function getUserInfo() {
	if(!isDetectUser){
		isDetectUser = 1;
		var req = getXmlHttp();
		req.onreadystatechange = function () {
			if (req.readyState == 4) {
				if (req.status == 200) {
					var res = eval('('+req.responseText+')');
					if(res.country_code && res.country_code == 'DE'){
						setStyleItem('.debanner','display','block','');
						console.log(res.country_code);
						isDEbanner = 1;
					}else{
						var userLang = navigator.language || navigator.userLanguage; 
						if(userLang == 'de-DE'){
							setStyleItem('.debanner','display','block','');
							isDEbanner = 1;
						}
						console.log(userLang);
					}
				}else{
					var userLang = navigator.language || navigator.userLanguage; 
					if(userLang == 'de-DE'){
						setStyleItem('.debanner','display','block','');
						isDEbanner = 1;
					}
					console.log(userLang);
				}
			}
		}
		req.open('GET.html', 'http://freegeoip.net/json/', true);
		req.send(null);
	}else{
		if(isDEbanner){
			setStyleItem('.debanner','display','block','');
		}
	}
}

function showAllEvents(sid) {
	var req = getXmlHttp()
	req.onreadystatechange = function () {
		if (req.readyState == 4) {
			if (req.status == 200) {
				var sec = document.querySelector('#secevents' + sid + ' .lshpane-sliders');

				if (sec) {
					sec.innerHTML += req.responseText;
					document.querySelector('#secevents' + sid).removeChild(document.querySelector('#secevents' + sid + ' .showallevents'));
					changeEventsTime(currentOffset);
				}
			}
		}
	}
	req.open('GET.html', '/static/all_events_section' + sid + '.html', true);
	req.send(null);
}

Element.prototype.getElements = function (selector) {
	var result = [];
	var nd = this.querySelectorAll(selector);
	for (var i = 0; i < nd.length; i++) result[i] = nd[i];
	return result;
};

function getElements(selector) {
	var result = [];
	var nd = document.querySelectorAll(selector);
	for (var i = 0; i < nd.length; i++) result[i] = nd[i];
	return result;
}

function setStyleItem(selector, property, value, before_prefix) {
	if (value) {
		var items = getElements(selector);
		for (var i = 0; i < items.length; i++) {
			if (items[i].style[property] != 'undefined') {
				items[i].style[property] = before_prefix + unescape(value);
			}
		}
	}
}

onReady(function () {
	var lshsection = getElementsByClassName("lshsection", document);
	var b;
	var re = /sections=((\d+)|,)*/;
	var cre = /cats=((\d+)|,)*/;
	var firstsection = 0;
	var sections_collections = {};
	var isCats = 0;

	runClock();

	if (a = re.exec(window.location.href)) {
		if (b = a[0].replace('sections=', '').split(',')) {
			for (var i = 0; i < b.length; i++) {
				if (b.length > 1 && b[i] && b[i] != 0 && Id('secid' + b[i])) {
					Id('secid' + b[i]).style.display = '';
				}
			}

			var isloadsection = 0;

			for (var i = 0; i < lshsection.length; i++) {
				if (b[0] && lshsection[i].id == 'secid' + b[0]) {
					if (b.length > 1) {
						removeClass(lshsection[i], "lshclosed");
						addClass(lshsection[i], "lshopen");
					}

					var lshdd = getElementsByClassName("lshdd", document);
					var id = lshsection[i].id.replace('secid', '');

					if (!document.getElementById('secevents' + id)) {
						isloadsection = 1;
						getSection(id);
					}
				}
			}

			if (!isloadsection) {
				var lshcurrent = getElementsByClassName("lshcurrent", document);
				lshcurrent[0].innerHTML = '<div class="notevents"><center>There are not events</center></div>';
			}
		}
	} else {
		if (a = cre.exec(window.location.href)) {
			if (b = a[0].replace('cats=', '').split(',')) {
				isCats = 1;
				for (var i = 0; i < b.length; i++) {
					for (var key in sec) {

						var v = sec[key].indexOf(parseInt(b[i]));

						if (!firstsection && v != -1)
							firstsection = key.replace('s', '');

						if (!sections_collections[key] && v != -1) {
							sections_collections[key] = [];
						}

						if (v != -1 && sections_collections[key].indexOf(parseInt(b[i])) == -1) {
							sections_collections[key].push(parseInt(b[i]));
							sections_collections[key].sort();
						}
					}
				}
			}
		}

		if (firstsection || isCats) {
			if (Object.keys(sections_collections).length > 1)
				for (var key in sections_collections) {
					Id('secid' + key.replace('s', '')).style.display = '';
				}

			removeClass(Id('secid' + firstsection), "lshclosed");
			addClass(Id('secid' + firstsection), "lshopen");

			if (!document.getElementById('secevents' + firstsection) && firstsection) {
				getSection(firstsection, sections_collections['s' + firstsection]);
			}

			if (!firstsection) {
				var lshcurrent = getElementsByClassName("lshcurrent", document);
				lshcurrent[0].innerHTML = '<div class="notevents"><center>There are not events</center></div>';
			}
		} else if (lshsection[0]) {
			for (var i = 0; i < lshsection.length; i++) {
				lshsection[i].style.display = '';
			}

			removeClass(lshsection[0], "lshclosed");
			addClass(lshsection[0], "lshopen");

			var lshdd = getElementsByClassName("lshdd", document);
			var id = lshsection[0].id.replace('secid', '');

			if (!document.getElementById('secevents' + id)) {
				getSection(id);
			}
		}
	}

	for (var i = 0; i < lshsection.length; i++) {
		lshsection[i].index = i;

		if (firstsection && sections_collections['s' + lshsection[i].id.replace('secid', '')] == 'undefined') {
			continue;
		}

		addEvent(lshsection[i], "click", function () {
			var lshdd = getElementsByClassName("lshdd", document);
			var lshopen = getElementsByClassName("lshopen", document);
			var id = this.id.replace('secid', '');

			for (var j = 0; j < lshdd.length; j++) {
				lshdd[j].style.display = 'none';
			}

			removeClass(lshopen[0], "lshopen");
			addClass(lshopen[0], "lshclosed");

			removeClass(this, "lshclosed");
			addClass(this, "lshopen");

			if (!document.getElementById('secevents' + id)) {
				if (firstsection)
					getSection(id, sections_collections['s' + id]);
				else
					getSection(id);
			} else {
				document.getElementById('secevents' + id).style.display = '';
			}
		});
	}

	changeEventsTime(currentOffset);
	
	//getUserInfo();
});

function animate(id, delta, from, to, dur) {
	var element = document.getElementById(id);
	var duration = dur || 400;
	var start = new Date().getTime();

	setTimeout(function () {
		var now = (new Date().getTime()) - start;
		var progress = now / duration;

		if (progress > 1)
			var result = to;
		else
			var result = (to - from) * delta(progress) + from;

		element.style.height = result + "px";

		if (progress < 1)
			setTimeout(arguments.callee, 10);
	}, 10);
}

function openEventNewTab(id,e){
	if (!e) e = window.event;

	if (!e.which && e.button) {
	  if (e.button & 1) e.which = 1
	  else if (e.button & 4) e.which = 2
	  else if (e.button & 2) e.which = 3
	} 
	
	if(e.which == 2){  
		var win = window.open(document.querySelector("#e" + id + " .open_event_tab").getAttribute('href'));
		window.focus();
	} 
}

function getEvent(id) {
	   
	if (getElements('#e' + id + ' .lshjpane-toggler-down').length > 0) {
		animate('event' + id, function (p) {
			return Math.pow(p, 2);
		}, document.getElementById("event" + id).clientHeight, 0);

		var lshtitle = getElementsByClassName("lshtitle", document);
		for (var i = 0; i < lshtitle.length; i++) {
			removeClass(lshtitle[i], "lshjpane-toggler-down");
			addClass(lshtitle[i], "lshjpane-toggler");
		}
		return;
	}

	var lshjpaneslider = getElements('.lshjpane-toggler-down');//getElementsByClassName("lshjpane-slider",document);

	for (var i = 0; i < lshjpaneslider.length; i++) {
		var sd = lshjpaneslider[i].parentNode.id.replace('e', '');
		animate('event' + sd, function (p) {
			return Math.pow(p, 2);
		}, document.getElementById("event" + sd).clientHeight, 0);
	}

	var lshtitle = getElementsByClassName("lshtitle", document);
	for (var i = 0; i < lshtitle.length; i++) {
		removeClass(lshtitle[i], "lshjpane-toggler-down");
		addClass(lshtitle[i], "lshjpane-toggler");
	}

	animate('event' + id, function (p) {
		return Math.pow(p, 2);
	}, 0, document.getElementById("event" + id).scrollHeight);

	getBets(id);

	eventtitle = getElementsByClassName("eventtitle" + id, document);
	removeClass(eventtitle[0], "lshjpane-toggler");
	addClass(eventtitle[0], "lshjpane-toggler-down");
}

function openwindow(url, width, height) {
	var rand = Math.floor(Math.random() * 1000000);
	window.open(url, "mywindow" + rand, "menubar=0,resizable=1,width=" + width + ",height=" + height);
}

function openWindow(url, width, height) {
	openwindow(url, width, height);
}

function sortEvents(sec) {
	var eventsDay = getElements('#secevents' + sec + ' div.events_day');

	for (var event_day in eventsDay) {
		if (!eventsDay[event_day] || typeof(eventsDay[event_day]) != "object") {
			continue;
		}

		var events = eventsDay[event_day].getElements('.lshpanel');
		var events_ob = [];

		for (var event in events) {
			var ret = document.querySelector("#" + events[event].id + " .original_time");

			if (!ret) {
				continue;
			}

			events_ob.push({"time":ret.innerHTML, "id":events[event].id, "html":events[event].innerHTML/*wrap.innerHTML*/});

			eventsDay[event_day].removeChild(events[event]);
		}

		events_ob.sort(function (a, b) {
			if (a.time < b.time)
				return -1;
			if (a.time > b.time)
				return 1;
			return 0;
		});

		for (var se in events_ob) {
			if (events_ob[se].id === undefined) {
				continue;
			}

			var newEl = document.createElement("div");
			newEl.innerHTML = events_ob[se].html;
			newEl.setAttribute('id', events_ob[se].id);
			newEl.setAttribute('class', 'lshpanel');
			eventsDay[event_day].appendChild(newEl);
		}
	}

	return true;
}

function changeEventsTime(offset) {
	var sections = getElements('.lshcurrent .lshdd');

	for (var sec in sections) {
		if (!sections[sec].id) continue;

		var sectionid = sections[sec].id.replace('secevents', '');
		var events = getElements('#' + sections[sec].id + ' .lshpanel');
		var events_day = getElements('#' + sections[sec].id + ' div.events_day');

		for (var ev in events) {
			if (!document.querySelector('#' + events[ev].id + ' .original_time')) continue;

			var original_time = document.querySelector('#' + events[ev].id + ' .original_time').innerHTML * 1000;
			var change_time = document.querySelector('#' + events[ev].id + ' .change_time').innerHTML * 1000;
			var original_datetime = new Date(original_time);
			var change_datetime = new Date(change_time);
			var new_datetime = new Date();

			change_datetime.setTime(change_datetime.getTime() - ((change_datetime.getTimezoneOffset() / -60) * 60 * 60 * 1000));
			new_datetime.setTime(original_datetime.getTime() - ((original_datetime.getTimezoneOffset() / -60) * 60 * 60 * 1000) + (offset * 60 * 60 * 1000));

			document.querySelector('#' + events[ev].id + ' .lshstart_time').innerHTML = new_datetime.getLSHFormatDate('%H:%M');
			document.querySelector('#' + events[ev].id + ' .date').innerHTML = new_datetime.getLSHFormatDate('%A (%d %B) %H:%M') + ' (GMT ' + (offset > 0 ? '+' : '') + offset + ')';

			if (!document.querySelector('#' + sections[sec].id + ' .d' + new_datetime.getLSHFormatDate('%d_%m_%Y'))) {
				var div = document.createElement('div');
				div.className = 'events_day d' + new_datetime.getLSHFormatDate('%d_%m_%Y');
				div.innerHTML = '<span class="date">' + new_datetime.getLSHFormatDate('%A (%d %B)') + '</span>';
				document.querySelector('#' + sections[sec].id + ' .lshpane-sliders').appendChild(div);
			}
			
			document.querySelector('#' + sections[sec].id + ' .d' + new_datetime.getLSHFormatDate('%d_%m_%Y')).appendChild(document.querySelector('#' + events[ev].id));

			document.querySelector('#' + events[ev].id + ' .change_time').innerHTML = new_datetime.getTime() / 1000;

			var new_date = document.querySelector('#' + sections[sec].id + ' .d' + new_datetime.getLSHFormatDate('%d_%m_%Y'));

			if (new_date && new_date.style.display == 'none') {
				document.querySelector('#' + sections[sec].id + ' .d' + new_datetime.getLSHFormatDate('%d_%m_%Y')).style.display = 'block';
			}

			orininal_datetime = null;
			change_datetime = null;
			new_datetime = null;
		}

		for (var ed in events_day) {
			if (!events_day[ed] || typeof(events_day[ed]) != "object") {
				continue;
			}

			if (!events_day[ed].getElements('.lshpanel').length) {
				events_day[ed].style.display = 'none';
			}
		}

		sortEvents(sections[sec].id);
	}
}

function setNewClock(time) {
	currentTime = time;
}

function changeTimeZone(offset) {
	var currentDate = new Date();

	currentDate.setHours(currentDate.getUTCHours());
	currentDate.setMinutes(currentDate.getUTCMinutes());
	currentDate.setSeconds(currentDate.getUTCSeconds());
	currentDate.setMilliseconds(currentDate.getUTCMilliseconds());

	if (offset) {
		var new_time = offset * 60 * 60 * 1000;
		for (var i = 0; i < document.getElementById('offset').length; i++) {
			if (document.getElementById('offset').options[i] && document.getElementById('offset').options[i].value == offset) {
				document.getElementById('offset').options[i].selected = true;
				document.getElementById('gmt-selected').innerHTML = document.getElementById('offset').options[i].innerHTML;
				break;
			}
		}
	} else {
		offset = parseFloat(document.getElementById("offset").value);
		var new_time = offset * 60 * 60 * 1000;
	}

	setNewClock(currentDate.getTime() + new_time);

	//save offest in cookie
	option = {};
	option.domain = document.domain;
	option.path = 'index.html';
	option.expires = 1825;
	cookie('coffset', offset, option);

	currentOffset = offset;
	
	changeEventsTimeAfterSearch(currentOffset);
}

function runClock() {
	var currentDate = new Date();
	var coffset = cookie('coffset');

	document.getElementById("inHour").innerHTML = currentDate.getUTCHours();
	document.getElementById("inMinute").innerHTML = currentDate.getUTCMinutes()
	document.getElementById("inSecond").innerHTML = currentDate.getUTCSeconds();

	currentTime = currentDate.getTime();

	if (coffset) {
		changeTimeZone(coffset);
	} else {
		var offset = getQueryVariable('offset', '');
		if (offset != '') {
			changeTimeZone(offset);
		} else {
			changeTimeZone(currentOffset);
		}
	}

	incClock();
}

function incClock() {
	currentTime = currentTime + 1000;

	var x = new Date(currentTime);
	var hours = x.getHours();
	var minutes = x.getMinutes()
	var secs = x.getSeconds();

	if (hours < 10) {
		hours = "0" + hours;
	}
	if (minutes < 10) {
		minutes = "0" + minutes;
	}
	if (secs < 10) {
		secs = "0" + secs;
	}

	document.getElementById("inHour").innerHTML = hours;
	document.getElementById("inMinute").innerHTML = minutes;
	document.getElementById("inSecond").innerHTML = secs;
	tim = setTimeout('incClock()', 1000);
}

function changeTime() {
	changeTimeZone();
	changeEventsTime(currentOffset);
}

function selectTimeZone(time){
	time = time * 1;
	for (var i = 0; i < document.getElementById('offset').length; i++) {
		if (document.getElementById('offset').options[i] && document.getElementById('offset').options[i].value == time) {
			document.getElementById('offset').options[i].selected = true;
			document.getElementById('gmt-selected').innerHTML = document.getElementById('offset').options[i].innerHTML;
			break;
		}
	}
	
	changeTimeZone();
	changeEventsTime(currentOffset);
	
	toggleD(document.getElementById('gmt-select-menu'));
}

function changeSearch(el) {
	/*
	clearTimeout(window.search_timeout_id);
	window.search_timeout_id = setTimeout(function () {
		loadSearchResult(el.value, 0)
	}, 400);
	*/
	loadSearchResult(el.value, 0);
}

function nextEvent() {
	var active = document.querySelector('#search .resultbox-bl li.active');
	var page = active.id.replace('page', '');

	if (document.querySelector('#search .resultbox-bl #page' + ((page * 1) + 5))) {
		loadSearchResult(document.querySelector('#search_value').value, ((page * 1) + 5));
	}
}

function prevEvent() {
	var active = document.querySelector('#search .resultbox-bl li.active');
	var page = active.id.replace('page', '');

	if (document.querySelector('#search .resultbox-bl #page' + ((page * 1) - 5))) {
		loadSearchResult(document.querySelector('#search_value').value, ((page * 1) - 5));
	}
}

function loadSearchResult(value, limitstart) {
	if (value && value.length >= 2) {
		var req = getXmlHttp()
		req.onreadystatechange = function () {
			if (req.readyState == 4) {
				if (req.status == 200) {
					var res = eval('(' + req.responseText + ')');

					document.querySelector('#search .results').innerHTML = '';
					document.querySelector('#search .resultbox').style['display'] = 'block';
					//document.querySelector('.search-close').style['display'] = 'inline-block';

					if (res.error) {
						document.querySelector('#search .results').innerHTML = '<li><h3>No results found</h3><a href="javascript:void(0)">' + res.error + '</a></li>';
						document.querySelector('#search .resultbox-bl').innerHTML = '';
					} else if (res.count > 0) {
						for (var i = 0; i < res.results.length; i++) {
							if (res.results[i] == undefined) continue;
							document.querySelector('#search .results').innerHTML = document.querySelector('#search .results').innerHTML + '<li><a onclick="openEvent(\'' + res.results[i].url + '\');return false;" href="javascript:void(0)"><h3>' + res.results[i].title + '</h3>' + res.results[i].text + '</a></li>';
						}

						if (document.querySelector('#search_value').value != value) {
							var pages = Math.ceil(res.count / 5);
							var pages_html = '';

							document.querySelector('#search .resultbox-bl').setAttribute('total', res.count);

							if (pages > 1) {
								pages_html = '<ul class="search_pagination">';
								pages_html = pages_html + '<li><a onclick="prevEvent()" href="javascript:void(0)" >Prev</a></li>';
								for (var i = 0; i < pages; i++) {
									pages_html = pages_html + '<li id="page' + (5 * i) + '" ><a onclick="loadSearchResult(\'' + value + '\',' + (5 * i) + ')" href="javascript:void(0)" >' + (i + 1) + '</a></li>';
								}
								pages_html = pages_html + '<li><a onclick="nextEvent()" href="javascript:void(0)" >Next</a></li>';
								pages_html = pages_html + '</ul>';

								document.querySelector('#search .resultbox-bl').innerHTML = pages_html;
							}
						}

						var active = document.querySelector('#search .resultbox-bl li.active');

						if (active) {
							removeClass(active, 'active');
						}

						addClass(document.querySelector('#search .resultbox-bl #page' + limitstart), 'active');
					} else {
						document.querySelector('#search .resultbox-bl').innerHTML = '';
						document.querySelector('#search .results').innerHTML = '<li><h3>No results found</h3></li>';
					}

					if (document.querySelector('#search_value').value != value) {
						document.querySelector('#search_value').value = value;
					}
				}
			}
		}

		req.open('GET.html', 'search57de.html?option=com_search&amp;tmpl=raw&amp;type=json&amp;ordering=&amp;searchphrase=all&amp;Itemid=207&amp;areas[]=event&amp;searchword=' + value + '&limitstart=' + limitstart, true);
		req.send(null);
	}
}

function openEventW(responseText){
	responseText = unescape(responseText);
	
	document.querySelector('.event-block').innerHTML = responseText.split('index743f.html?option=com_lsh').join('index1743f.html?option=com_lsh');
	document.querySelector('.component').style['display'] = 'none';
	document.querySelector('.event-container').style['display'] = 'block';
}

function openEvent(url) {
	/*
	var script = document.createElement('script');
	script.type = 'text/javascript';
	script.src = window.location.href+url.replace('/index.php', 'search.php') + '&offset=' + document.querySelector('#offset').value + '&format=raw&type=jsonp';
	document.getElementsByTagName('head')[0].appendChild(script);
	*/


	var re = /option=com_lsh&view=event&id=(\d+)/;

	if (!re.test(url)) {
		window.location.assign(url);
		return true;
	}

	var req = getXmlHttp();
	req.onreadystatechange = function () {
		if (req.readyState == 4) {
			if (req.status == 200) {
				document.querySelector('.event-block').innerHTML = req.responseText.split('index743f.html?option=com_lsh').join('index1743f.html?option=com_lsh');
				document.querySelector('.component').style['display'] = 'none';
				document.querySelector('.event-container').style['display'] = 'block';
				
				changeEventsTimeAfterSearch(currentOffset);
			}
		}
	}
	req.open('GET.html', url.replace('index-2.html', 'search.html') + '&format=raw', true);
	req.send(null);

	return true;
}

function showEvents() {
	document.querySelector('.component').style['display'] = 'inline-table';
	document.querySelector('.event-container').style['display'] = 'none';
}

function resetA() {
	document.querySelector('.resultbox').style['display'] = 'none';
	//document.querySelector('.search-close').style['display'] = 'none';
	document.querySelector('#search .searchfield').value = 'search...';
	document.querySelector('#search .results').innerHTML = '';
	document.querySelector('#search .resultbox-bl').innerHTML = '';
}

function changeEventsTimeAfterSearch(offset) {
	if(!document.querySelector('.event-block').innerHTML.length) return;
	
	var original_time = document.querySelector('.event-block .original_time').innerHTML * 1000;
	var change_time = document.querySelector('.event-block .change_time').innerHTML * 1000;
	var original_datetime = new Date(original_time);
	var change_datetime = new Date(change_time);
	var new_datetime = new Date();

	change_datetime.setTime(change_datetime.getTime() - ((change_datetime.getTimezoneOffset() / -60) * 60 * 60 * 1000));
	new_datetime.setTime(original_datetime.getTime() - ((original_datetime.getTimezoneOffset() / -60) * 60 * 60 * 1000) + (offset * 60 * 60 * 1000));

	document.querySelector('.event-block .date').innerHTML = new_datetime.getLSHFormatDate('%A (%d %B) %H:%M') + ' (GMT ' + (offset > 0 ? '+' : '') + offset + ')';

	document.querySelector('.event-block .change_time').innerHTML = new_datetime.getTime() / 1000;
}